<template>
  <div class="coupontype cart2-coupon">
          <swiper :options="swiperOption" class="swiper-box swiper-box-c2">
              <swiper-slide class="swiper-item">
                 <volume :data="Conponable" :info='info1' :Clickok='true'></volume>
              </swiper-slide>
              <swiper-slide class="swiper-item">
                 <volume :data="ConponUnable" :info='info2'></volume>
              </swiper-slide>
             <div class="swiper-pagination-cart2" :class="posL" slot="pagination"  ></div>
        </swiper>
        <div v-show="coupontypeZw && wz" class="coupontype-zw" @click="useFn">
          <div>立即使用</div>5
        </div>
  </div>
</template>
<script>
  import { mapActions, mapGetters} from 'vuex'
  import {swiper, swiperSlide} from 'vue-awesome-swiper'
  import { Cart2storecoupon } from '@/service/getData'
  import Volume from './volume'
  var TAB_NAME = ['可使用', '不可用'];
  var Info = '暂无可使用的优惠券~';
  export default {
    data(){
      return{
          posL: '',
          Conponable:[],
          ConponUnable:[],
          info1:'',
          info2:'',
          info3:'',
          expired: true,
          coupontypeZw: true,
          wz: true,

          swiperOption: {
              pagination: '.swiper-pagination-cart2',
              paginationClickable: true,
              paginationBulletRender(swiper, index, className) {
                return  `<span class="${className} swiper-pagination-bullet-custom">${TAB_NAME[index]}</span>`;
              },

              onTransitionStart: swiper => {
                this.posL = 'active-'+swiper.realIndex;
                if(swiper.realIndex == 1) {
                  this.coupontypeZw = false
                }
                if(swiper.realIndex == 0) {
                  this.coupontypeZw = true
                }
              }
            }
      }
    },
    created(){
      this.init()
      this.$nextTick(() => {
        var i =  $('.swiper-box-c2 .swiper-wrapper .swiper-item');
        var z =  $('.coupontype-zw');
        var w = $('.swiper-box-c2 .swiper-wrapper');
         i.eq(0).height(
           z.offset().top-w.offset().top
        )
        i.eq(1).height(
           z.offset().top-w.offset().top+z.height()
        )

      })
    },
    computed: {
      ...mapGetters({
        position: 'position'
      }),
    },
    methods:{
        ...mapActions([
          'useFn'
        ]),
        init(){


          this.Cart2storecouponFn('/app/cardcoupon/private/queryCouponListInfo.do')

        },
        Cart2storecouponFn(url) {
            Cart2storecoupon({
              data: {
                app: 'wap',
                appVersion: '3.2.2',
                cityId: this.position.cityCode
              },
              url: url
            })
            .then((rep) => {
              let data1 = rep.data;

              if(!data1) return;

              var cl = data1.couponList;
              if(cl && toString.call(cl) == "[object Array]") {
                 var ableNum = 0,
                    unableNum = 0;
                    var ablearr = []
                    var unablearr = []
                    for(var i = 0; i < cl.length; i++) {
                      if(cl[i].usefulFlag == '1') {
                        if(cl[i].usedFlag == '1'){
                          cl[i].cheack = 'cheacked'
                        }
                        ablearr.push(cl[i])
                        ableNum++
                      }else if(cl[i].usefulFlag == '0') {
                        unablearr.push(cl[i])
                        unableNum++
                      }
                    }
                    if(ablearr.length == 0) {
                      this.wz = false
                    }

                    if(ableNum == 0) {
                        this.info1 = Info
                    }
                    if(unableNum == 0) {
                        this.info2 = Info
                    }
                    this.Conponable = ablearr
                    this.ConponUnable = unablearr

                    if (ableNum > 0) {
                      TAB_NAME[0] = '可使用('+ableNum+')'
                    }
                    if(unableNum > 0) {
                      TAB_NAME[1] = '不可用('+unableNum+')'
                    }

                    setTimeout(() => {
                       var s = $('.swiper-pagination-cart2 span');
                          if(ableNum > 0) {
                            s.eq(0).html('可使用('+ableNum+')');
                          }
                          if(unableNum > 0) {
                            s.eq(1).html( '不可用('+unableNum+')');
                          }
                     }, 500)

              } else {
                this.wz = false
                this.info1 = Info
                this.info2 = Info
              }
            })
        }
        // useFn(){
        //   var arr = [];
        //   for(var i = 0; i < this.data.length; i++) {
        //     if(this.Conponable[i].cheack == 'cheacked') {
        //         arr.push(this.Conponable[i].couponNumber)
        //     }
        //   }

        //   this.$store.dispatch('private1', arr);
        // }
    },
    components: {
      swiper,
      swiperSlide,
      Volume
    }
  }
</script>
<style lang="scss">
  @function _($px) {
        $rem: $px/50;
        @return #{$rem}rem;
   }
  .coupontype {
    overflow: hidden;
  }
  .swiper-box-c2 {
    height: 100%
  }
  .swiper-box-c2  .swiper-wrapper .swiper-item {
    overflow: hidden;
    overflow-y: auto
  }
  .coupontype-zw {
    background-color: #fff;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: _(100);
    z-index: 11;

      & > div {
        width: _(702);
        margin: _(10) auto 0;
        height: _(80);
        line-height: _(80);
        background-color: #ff782d;
        border-radius: _(4);
        text-align: center;
        color: #fff;
        font-size: _(30);
      }

  }
  .swiper-box-c2 .swiper-wrapper {
     top: _(80);
  }
  .swiper-pagination-cart2 {
    position: absolute;
    top: 0;
    width: 100%;
    height: _(80);
  }
  .swiper-pagination-cart2 span{
    width: 50%;
    height: _(80);
    line-height: _(80);
    font-size: _(26);
    display:inline-block;
    margin:0 !important;
    background-color:#fff;
    border-radius: 0;
    opacity: 1 ;
    text-align: center;
    color:#444;
    letter-spacing: _(-0.16);
  }
  .swiper-pagination-cart2 span.swiper-pagination-bullet-active {
    color:#ff782d;
  }

  .swiper-pagination-cart2:after {
    position: absolute;
    content: '';
    left: 15%;
    bottom: 0;
    width: _(143);
    height: _(4);
    background-color: #ff782d;
    transition: left 0.1s;
  }
  .swiper-pagination-cart2.active-1:after {
    left: 65%
  }
 .swiper-pagination-bullet{
   position: relative;
 }
.bg-cl{
    color:#fff;
    background: #ff782d;
    padding: _(1) _(10);
    position: absolute;
    border-radius:_(20);
    line-height: _(30);
    top:.1rem
}


</style>
<style lang="scss" scoped>
    @function _($px) {
        $rem: $px/50;
        @return #{$rem}rem;
   }

   .conpontype-tab {
      ul {
        background-color: #fff;
        overflow: hidden;

          li {
              float: left;
              width: 33.33%;
              text-align: center;
          }
      }
   }

</style>
